home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
mpeg
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
5KB
|
255 lines
/**********************************************************************
*. This file is part of BIT shareware package.
*
* Copyright(c) 1993, 1994 by T.C. Zhao
* All rights reserved.
*.
*
**********************************************************************/
#include "video.h"
#include "proto.h"
#include <sys/types.h>
#include <signal.h>
#include <netinet/in.h>
#include <stdlib.h>
#include "util.h"
#include "dither.h"
#define BUF_LENGTH 80000 /* Define buffer length. */
double realTimeStart;
int totNumFrames = 0;
FILE *input; /* Global file pointer to incoming data. */
int EOF_flag = 0;
int loopFlag; /* Loop flag. */
int quietFlag; /* Quiet flag. */
int noDisplayFlag; /* Display image on screen? */
int run_in_background;
int seek_only;
jmp_buf env; /* Setjmp/Longjmp env. */
jmp_buf errjmp;
int ditherType = FULL_COLOR_DITHER;
void
frame_re_init(void)
{
EOF_flag = 0;
curBits = 0;
bitOffset = 0;
bufLength = 0;
bitBuffer = NULL;
totNumFrames = 0;
}
/***** Initialize the entire decoder system *****************/
void
mpeg_system_init(void)
{
static mpegsysinit;
if (!mpegsysinit)
{
LUM_RANGE = 8;
CR_RANGE = CB_RANGE = 4;
lum_values = (int *) malloc(LUM_RANGE * sizeof(int));
cr_values = (int *) malloc(CR_RANGE * sizeof(int));
cb_values = (int *) malloc(CB_RANGE * sizeof(int));
ditherType = FULL_COLOR_DITHER;
init_tables();
InitColorDither();
}
mpegsysinit = 1;
}
void
set_video_stream(FILE * fp)
{
input = fp;
}
static VidStream *theStream;
extern void glDisplay(VidStream *);
static char *parse_command_line(int, char **argv);
/***********************************************************************
* Main
* Call mpegVidRsrc to get next frame and glDisplay to
* display the frame.
**********************************************************************/
int
main(int argc, char **argv)
{
char *name;
if ((name = parse_command_line(argc, argv)))
input = fopen(name, "r");
if (!input)
{
fprintf(stderr, "bad file\n");
exit(1);
}
/* set up error handler */
if (setjmp(errjmp))
{
fprintf(stderr, "Can't continue");
exit(0);
}
do
{
theStream = NewVidStream(BUF_LENGTH);
mpeg_system_init();
if (!(mpegVidRsrc(0, theStream)))
continue;
realTimeStart = ReadSysClock();
while (mpegVidRsrc(0, theStream))
{
totNumFrames++;
if (!quietFlag)
fprintf(stderr, "%d\r", totNumFrames);
glDisplay(theStream);
}
PrintTimeInfo();
if (loopFlag)
{
DestroyVidStream(theStream);
theStream = 0;
rewind(input);
reset_mpeg_stream();
frame_re_init();
}
}
while (loopFlag);
return 0;
}
/******************************************************************
* Handle command line
*****************************************************************/
static char *options = "[-nlhbq -m f]";
static char *optstr = "nlhbqm:";
static char *helps[] =
{
"\t-h: for this help", "\t-l: loop back",
"\t-n: no display", "\t-b: run in background",
"\t-q: quiet. No timing stat",
#if 0
"\t-d i: frame delay. In milli-seconds\n",
#endif
"\t-m f: magnigication",
" Use SPACE key to pause",
" Use RIGHTMOUSE for pop-up menu",
0
};
static void
usage(char *cmd, int die, int v)
{
char **p = helps;
fprintf(stderr, "%s: Part of BIT package\n", cmd);
fprintf(stderr, "Usage: %s %s mpegfile\n", cmd, options);
if (v)
{
while (*p)
{
fprintf(stderr, "%s\n", *p);
p++;
}
}
if (die)
exit(1);
}
extern char *optarg;
extern int optind, opterr;
static char *
parse_command_line(int argc, char **argv)
{
int c;
float mf;
opterr = 0;
if (argc < 2)
usage(*argv, 1, 0);
while ((c = getopt(argc, argv, optstr)) != EOF)
{
switch (c)
{
case 'h':
usage(argv[0], 1, 1);
break;
case 'l':
loopFlag = 1;
break;
case 'n':
noDisplayFlag = 1;
break;
case 'b':
run_in_background = 1;
break;
case 'q':
quietFlag = 1;
break;
case 'm': /* maginification */
if ((mf = atof(optarg)) > 0)
set_maginification(mf);
break;
default:
usage(argv[0], 1, 0);
}
}
return (optind < argc) ? argv[optind] : 0;
}
#include <sys/time.h>
double
ReadSysClock()
{
struct timeval tv;
(void) gettimeofday(&tv, (struct timezone *) NULL);
return (tv.tv_sec + tv.tv_usec / 1000000.0);
}
void
PrintTimeInfo()
{
double spent;
spent = ReadSysClock() - realTimeStart;
if (!quietFlag)
{
printf("\nReal Time Spent (After Initializations): %f secs.\n", spent);
printf("Avg. Frames/Sec: %f\n", ((double) totNumFrames) / spent);
}
}